package com.wang.project.controller;


import com.wang.project.common.BaseResponse;
import com.wang.project.common.ResultUtils;
import com.wang.project.model.dto.integral.IntegralExchangeInterfaceRequest;
import com.wang.project.model.vo.integral.IntegralExchangeInterfaceVO;
import com.wang.project.model.vo.integral.IntegralExchangeRefreshKeyVO;
import com.wang.project.model.vo.integral.IntegralSignInVO;
import com.wang.project.model.vo.integral.IntegralVO;
import com.wang.project.service.IntegralService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 积分操作
 */
@RestController
@RequestMapping("/integral")
public class IntegralController {

    @Resource
    private IntegralService integralService;

    /**
     * 连续签到积分额度阶梯
     */
    private Map<Integer, Integer> integerMap = new HashMap<>();

    {
        // key : 天数  value: 积分数
        integerMap.put(0, 1);
        integerMap.put(1, 1);
        integerMap.put(2, 1);
        integerMap.put(3, 2);
        integerMap.put(4, 2);
        integerMap.put(5, 2);
        integerMap.put(6, 2);
        integerMap.put(7, 3);
    }

    /**
     * 用户点击签到 签到一次可以获取多少积分，如果连续连续，是否增加获取的积分额
     *
     * @param request
     * @return
     */
    @ApiOperation("用户签到")
    @PostMapping("/signIn")
    public BaseResponse<IntegralSignInVO> userSignIn(HttpServletRequest request) {
        return ResultUtils.success(integralService.signIn(request));
    }

    /**
     * 兑换指定接口调用次数
     *
     * @param integralExchangeInterfaceRequest
     * @param request
     * @return
     */
    @ApiOperation("积分接口兑换")
    @PostMapping("/interface/exchange")
    public BaseResponse<IntegralExchangeInterfaceVO> integralExchangeToInterface(IntegralExchangeInterfaceRequest integralExchangeInterfaceRequest, HttpServletRequest request) {
        return ResultUtils.success(integralService.interfaceExchangeByIntegral(integralExchangeInterfaceRequest, request));
    }

    /**
     * 返回积分兑换的接口列表
     */
    @ApiOperation("返回积分兑换的接口列表")
    @GetMapping("/list")
    public BaseResponse<List<IntegralVO>> integralList(HttpServletRequest request) {
        return ResultUtils.success(integralService.integralList(request));
    }

    /**
     * 兑换永久刷新key服务
     */
    @ApiOperation("积分刷新key兑换")
    @PostMapping("/refreshKey/exchange")

    public BaseResponse<IntegralExchangeRefreshKeyVO> integralExchangeToFreshKey(HttpServletRequest request) {
        return ResultUtils.success(integralService.freshKeyExchangeByIntegral(request));
    }


}
